<div class="layuimini-main">

    <div class="layui-form layuimini-form" lay-filter="main">
        <div class="layui-form-item">
            <label class="layui-form-label required">账号</label>
            <div class="layui-input-block">
                <input type="text" name="id" lay-verify="required" lay-reqtext="账号不能为空" placeholder="请输入账号" value="" disabled class="layui-input layui-disabled">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label required">姓名</label>
            <div class="layui-input-block">
                <input type="text" name="name" lay-verify="required" lay-reqtext="姓名不能为空" placeholder="请输入姓名" value="" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label required">身份</label>
            <div class="layui-input-block">
                <select name="limit" lay-verify="required" lay-reqtext="身份不能为空">
                    <option id="empty" value=""></option>
                    <option id="管理员" value="1">管理员</option>
                    <option id="学生" value="2">学生</option>
                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
            </div>
        </div>
    </div>
</div>
<script>
    layui.use(['form', 'table'], function () {
        var form = layui.form,
            layer = layui.layer,
            table = layui.table,
            $ = layui.$;

        form.val("main", {
            "ID":window.sessionStorage.getItem('user.ID'),
            "name":window.sessionStorage.getItem('user.name'),
            "limit":window.sessionStorage.getItem('user.limit')
        });

        /**
         * 初始化表单，要加上，不然刷新部分组件可能会不加载
         */
        form.render();

        // 当前弹出层，防止ID被覆盖
        var parentIndex = layer.index;

        //监听提交
        form.on('submit(saveBtn)', function (data) {

            $.ajax({
                url:'/index/admin/editUserJson'
                ,type: 'POST'
                ,data: data.field
                ,success:function (res) {
                    if(res.code == "1"){
                        var index = layer.msg(res.message, {
                            icon: 1
                        }, function () {

                            // 关闭弹出层
                            layer.close(index);
                            layer.close(parentIndex);
                            window.parent.location.reload();
                        });
                    }else{
                        layer.msg(res.message, {icon: 2});
                    }
                }
            });

            return false;
        });

    });
</script>